package com.ken.android.music.mvp.B;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.ken.android.music.mvp.B.I.IBaseView;


/**
 * Created by Administrator on 2016/11/27.
 */

public abstract class BaseMvpActivity<V extends IBaseView, P extends BasePresenter<V>> extends AppCompatActivity
        implements IBaseView {

    protected P mPresenter;
    int layoutId;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = createPresenter();
        if (mPresenter != null) {
            mPresenter.attachView((V) this);
        }
        setContentView(onSetContent());
        if (layoutId != 0) {
            onSetContent();
        }
        initView(null);
        initData();
    }

    @Override
    public int onSetContent() {
        return 0;
    }

    @Override
    public void initView(View view) {

    }

    @Override
    public void initData() {

    }

    public abstract P createPresenter();


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mPresenter != null) {
            mPresenter.detachView();
        }
        mPresenter = null;
    }

    @Override
    public Context obtainContext() {
        return this;
    }

    @Override
    public Context obtainApplicationContext() {
        return getApplicationContext();
    }

}
